<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Module: Technoweenie::AttachmentFu::Backends::S3Backend</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href="../../../.././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Module</strong></td>
          <td class="class-name-in-header">Technoweenie::AttachmentFu::Backends::S3Backend</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../../../../files/vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu/backends/s3_backend_rb.html">
                vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu/backends/s3_backend.rb
                </a>
        <br />
            </td>
        </tr>

        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">

    <div id="description">
      <h1>AWS::S3 Storage Backend</h1>
<p>
Enables use of <a href="http://aws.amazon.com/s3">Amazon's Simple Storage
Service</a> as a storage mechanism
</p>
<h2>Requirements</h2>
<p>
Requires the <a href="http://amazon.rubyforge.org">AWS::S3 Library</a> for
S3 by Marcel Molina Jr. installed either as a gem or a as a Rails plugin.
</p>
<h2>Configuration</h2>
<p>
Configuration is done via <tt>RAILS_ROOT/config/amazon_s3.yml</tt> and is
loaded according to the <tt>RAILS_ENV</tt>. The minimum connection options
that you must specify are a bucket name, your access key id and your secret
access key. If you don&#8216;t already have your access keys, all you need
to sign up for the S3 service is an account at Amazon. You can sign up for
S3 and get access keys by visiting <a
href="http://aws.amazon.com/s3">aws.amazon.com/s3</a>.
</p>
<p>
Example configuration (RAILS_ROOT/config/amazon_s3.yml)
</p>
<pre>
  development:
    bucket_name: appname_development
    access_key_id: &lt;your key&gt;
    secret_access_key: &lt;your key&gt;

  test:
    bucket_name: appname_test
    access_key_id: &lt;your key&gt;
    secret_access_key: &lt;your key&gt;

  production:
    bucket_name: appname
    access_key_id: &lt;your key&gt;
    secret_access_key: &lt;your key&gt;
</pre>
<p>
You can change the location of the config path by passing a full path to
the :s3_config_path option.
</p>
<pre>
  has_attachment :storage =&gt; :s3, :s3_config_path =&gt; (RAILS_ROOT + '/config/s3.yml')
</pre>
<h3>Required configuration parameters</h3>
<ul>
<li><tt>:access_key_id</tt> - The access key id for your S3 account. Provided
by Amazon.

</li>
<li><tt>:secret_access_key</tt> - The secret access key for your S3 account.
Provided by Amazon.

</li>
<li><tt>:bucket_name</tt> - A unique bucket name (think of the bucket_name as
being like a database name).

</li>
</ul>
<p>
If any of these required arguments is missing, a MissingAccessKey exception
will be raised from AWS::S3.
</p>
<h2>About bucket names</h2>
<p>
Bucket names have to be globaly unique across the S3 system. And you can
only have up to 100 of them, so it&#8216;s a good idea to think of a bucket
as being like a database, hence the correspondance in this implementation
to the development, test, and production environments.
</p>
<p>
The number of objects you can store in a bucket is, for all intents and
purposes, unlimited.
</p>
<h3>Optional configuration parameters</h3>
<ul>
<li><tt>:server</tt> - The server to make requests to. Defaults to
<tt>s3.amazonaws.com</tt>.

</li>
<li><tt>:port</tt> - The port to the requests should be made on. Defaults to 80
or 443 if <tt>:use_ssl</tt> is set.

</li>
<li><tt>:use_ssl</tt> - If set to true, <tt>:port</tt> will be implicitly set
to 443, unless specified otherwise. Defaults to false.

</li>
</ul>
<h2>Usage</h2>
<p>
To specify S3 as the storage mechanism for a model, set the
acts_as_attachment <tt>:storage</tt> option to <tt>:s3</tt>.
</p>
<pre>
  class Photo &lt; ActiveRecord::Base
    has_attachment :storage =&gt; :s3
  end
</pre>
<h3>Customizing the path</h3>
<p>
By default, files are prefixed using a pseudo hierarchy in the form of
<tt>:table_name/:id</tt>, which results in S3 urls that look like:
http(s)://:server/:bucket_name/:table_name/:id/:filename with :table_name
representing the customizable portion of the path. You can customize this
prefix using the <tt>:path_prefix</tt> option:
</p>
<pre>
  class Photo &lt; ActiveRecord::Base
    has_attachment :storage =&gt; :s3, :path_prefix =&gt; 'my/custom/path'
  end
</pre>
<p>
Which would result in URLs like
<tt>http(s)://:server/:bucket_name/my/custom/path/:id/:filename.</tt>
</p>
<h3>Permissions</h3>
<p>
By default, files are stored on S3 with public access permissions. You can
customize this using the <tt>:s3_access</tt> option to
<tt>has_attachment</tt>. Available values are <tt>:private</tt>,
<tt>:public_read_write</tt>, and <tt>:authenticated_read</tt>.
</p>
<h3>Other options</h3>
<p>
Of course, all the usual configuration options apply, such as content_type
and thumbnails:
</p>
<pre>
  class Photo &lt; ActiveRecord::Base
    has_attachment :storage =&gt; :s3, :content_type =&gt; ['application/pdf', :image], :resize_to =&gt; 'x50'
    has_attachment :storage =&gt; :s3, :thumbnails =&gt; { :thumb =&gt; [50, 50], :geometry =&gt; 'x50' }
  end
</pre>
<h3>Accessing S3 URLs</h3>
<p>
You can get an object&#8216;s URL using the <a
href="S3Backend.html#M000029">s3_url</a> accessor. For example, assuming
that for your postcard app you had a bucket name like
&#8216;postcard_world_development&#8217;, and an attachment model called
Photo:
</p>
<pre>
  @postcard.s3_url # =&gt; http(s)://s3.amazonaws.com/postcard_world_development/photos/1/mexico.jpg
</pre>
<p>
The resulting url is in the form:
http(s)://:server/:bucket_name/:table_name/:id/:file. The optional
thumbnail argument will output the thumbnail&#8216;s filename (if any).
</p>
<p>
Additionally, you can get an object&#8216;s base path relative to the
bucket root using <tt><a href="S3Backend.html#M000027">base_path</a></tt>:
</p>
<pre>
  @photo.file_base_path # =&gt; photos/1
</pre>
<p>
And the full path (including the filename) using <tt><a
href="S3Backend.html#M000028">full_filename</a></tt>:
</p>
<pre>
  @photo.full_filename # =&gt; photos/
</pre>
<p>
Niether <tt><a href="S3Backend.html#M000027">base_path</a></tt> or <tt><a
href="S3Backend.html#M000028">full_filename</a></tt> include the bucket
name as part of the path. You can retrieve the bucket name using the
<tt>bucket_name</tt> method.
</p>

    </div>


   </div>

    <div id="method-list">
      <h3 class="section-bar">Methods</h3>

      <div class="name-list">
      <a href="#M000026">attachment_path_id</a>&nbsp;&nbsp;
      <a href="#M000031">authenticated_s3_url</a>&nbsp;&nbsp;
      <a href="#M000027">base_path</a>&nbsp;&nbsp;
      <a href="#M000032">create_temp_file</a>&nbsp;&nbsp;
      <a href="#M000033">current_data</a>&nbsp;&nbsp;
      <a href="#M000037">destroy_file</a>&nbsp;&nbsp;
      <a href="#M000025">filename=</a>&nbsp;&nbsp;
      <a href="#M000028">full_filename</a>&nbsp;&nbsp;
      <a href="#M000023">hostname</a>&nbsp;&nbsp;
      <a href="#M000024">port_string</a>&nbsp;&nbsp;
      <a href="#M000022">protocol</a>&nbsp;&nbsp;
      <a href="#M000030">public_filename</a>&nbsp;&nbsp;
      <a href="#M000038">rename_file</a>&nbsp;&nbsp;
      <a href="#M000035">s3_hostname</a>&nbsp;&nbsp;
      <a href="#M000036">s3_port_string</a>&nbsp;&nbsp;
      <a href="#M000034">s3_protocol</a>&nbsp;&nbsp;
      <a href="#M000029">s3_url</a>&nbsp;&nbsp;
      <a href="#M000039">save_to_storage</a>&nbsp;&nbsp;
      </div>
    </div>

  </div>


    <!-- if includes -->
    <div id="includes">
      <h3 class="section-bar">Included Modules</h3>

      <div id="includes-list">
        <span class="include-name">AWS::S3</span>
      </div>
    </div>

    <div id="section">

    <div id="class-list">
      <h3 class="section-bar">Classes and Modules</h3>

      Module <a href="S3Backend/ClassMethods.html" class="link">Technoweenie::AttachmentFu::Backends::S3Backend::ClassMethods</a><br />
Class <a href="S3Backend/ConfigFileNotFoundError.html" class="link">Technoweenie::AttachmentFu::Backends::S3Backend::ConfigFileNotFoundError</a><br />
Class <a href="S3Backend/RequiredLibraryNotFoundError.html" class="link">Technoweenie::AttachmentFu::Backends::S3Backend::RequiredLibraryNotFoundError</a><br />

    </div>




      


    <!-- if method_list -->
    <div id="methods">
      <h3 class="section-bar">Public Class methods</h3>

      <div id="method-M000023" class="method-detail">
        <a name="M000023"></a>

        <div class="method-heading">
          <a href="#M000023" class="method-signature">
          <span class="method-name">hostname</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000023-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000023-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu/backends/s3_backend.rb, line 160</span>
160:         <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">hostname</span>
161:           <span class="ruby-ivar">@hostname</span> <span class="ruby-operator">||=</span> <span class="ruby-identifier">s3_config</span>[<span class="ruby-identifier">:server</span>] <span class="ruby-operator">||</span> <span class="ruby-constant">AWS</span><span class="ruby-operator">::</span><span class="ruby-constant">S3</span><span class="ruby-operator">::</span><span class="ruby-constant">DEFAULT_HOST</span>
162:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000024" class="method-detail">
        <a name="M000024"></a>

        <div class="method-heading">
          <a href="#M000024" class="method-signature">
          <span class="method-name">port_string</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000024-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000024-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu/backends/s3_backend.rb, line 164</span>
164:         <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">port_string</span>
165:           <span class="ruby-ivar">@port_string</span> <span class="ruby-operator">||=</span> <span class="ruby-identifier">s3_config</span>[<span class="ruby-identifier">:port</span>] <span class="ruby-operator">==</span> (<span class="ruby-identifier">s3_config</span>[<span class="ruby-identifier">:use_ssl</span>] <span class="ruby-operator">?</span> <span class="ruby-value">443</span> <span class="ruby-operator">:</span> <span class="ruby-value">80</span>) <span class="ruby-operator">?</span> <span class="ruby-value str">''</span> <span class="ruby-operator">:</span> <span class="ruby-node">&quot;:#{s3_config[:port]}&quot;</span>
166:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000022" class="method-detail">
        <a name="M000022"></a>

        <div class="method-heading">
          <a href="#M000022" class="method-signature">
          <span class="method-name">protocol</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000022-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000022-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu/backends/s3_backend.rb, line 156</span>
156:         <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">protocol</span>
157:           <span class="ruby-ivar">@protocol</span> <span class="ruby-operator">||=</span> <span class="ruby-identifier">s3_config</span>[<span class="ruby-identifier">:use_ssl</span>] <span class="ruby-operator">?</span> <span class="ruby-value str">'https://'</span> <span class="ruby-operator">:</span> <span class="ruby-value str">'http://'</span>
158:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <h3 class="section-bar">Public Instance methods</h3>

      <div id="method-M000026" class="method-detail">
        <a name="M000026"></a>

        <div class="method-heading">
          <a href="#M000026" class="method-signature">
          <span class="method-name">attachment_path_id</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
The attachment ID used in the full path of a file
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000026-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000026-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu/backends/s3_backend.rb, line 189</span>
189:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">attachment_path_id</span>
190:           ((<span class="ruby-identifier">respond_to?</span>(<span class="ruby-identifier">:parent_id</span>) <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">parent_id</span>) <span class="ruby-operator">||</span> <span class="ruby-identifier">id</span>).<span class="ruby-identifier">to_s</span>
191:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000031" class="method-detail">
        <a name="M000031"></a>

        <div class="method-heading">
          <a href="#M000031" class="method-signature">
          <span class="method-name">authenticated_s3_url</span><span class="method-args">(*args)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
All private objects are accessible via an authenticated GET request to the
S3 servers. You can generate an authenticated url for an object like this:
</p>
<pre>
  @photo.authenticated_s3_url
</pre>
<p>
By default authenticated urls expire 5 minutes after they were generated.
</p>
<p>
Expiration options can be specified either with an absolute time using the
<tt>:expires</tt> option, or with a number of seconds relative to now with
the <tt>:expires_in</tt> option:
</p>
<pre>
  # Absolute expiration date (October 13th, 2025)
  @photo.authenticated_s3_url(:expires =&gt; Time.mktime(2025,10,13).to_i)

  # Expiration in five hours from now
  @photo.authenticated_s3_url(:expires_in =&gt; 5.hours)
</pre>
<p>
You can specify whether the url should go over SSL with the
<tt>:use_ssl</tt> option. By default, the ssl settings for the current
connection will be used:
</p>
<pre>
  @photo.authenticated_s3_url(:use_ssl =&gt; true)
</pre>
<p>
Finally, the optional thumbnail argument will output the thumbnail&#8216;s
filename (if any):
</p>
<pre>
  @photo.authenticated_s3_url('thumbnail', :expires_in =&gt; 5.hours, :use_ssl =&gt; true)
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000031-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000031-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu/backends/s3_backend.rb, line 244</span>
244:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">authenticated_s3_url</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">args</span>)
245:           <span class="ruby-identifier">thumbnail</span> = <span class="ruby-identifier">args</span>.<span class="ruby-identifier">first</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">String</span>) <span class="ruby-operator">?</span> <span class="ruby-identifier">args</span>.<span class="ruby-identifier">first</span> <span class="ruby-operator">:</span> <span class="ruby-keyword kw">nil</span>
246:           <span class="ruby-identifier">options</span>   = <span class="ruby-identifier">args</span>.<span class="ruby-identifier">last</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Hash</span>)    <span class="ruby-operator">?</span> <span class="ruby-identifier">args</span>.<span class="ruby-identifier">last</span>  <span class="ruby-operator">:</span> {}
247:           <span class="ruby-constant">S3Object</span>.<span class="ruby-identifier">url_for</span>(<span class="ruby-identifier">full_filename</span>(<span class="ruby-identifier">thumbnail</span>), <span class="ruby-identifier">bucket_name</span>, <span class="ruby-identifier">options</span>)
248:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000027" class="method-detail">
        <a name="M000027"></a>

        <div class="method-heading">
          <a href="#M000027" class="method-signature">
          <span class="method-name">base_path</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
The pseudo hierarchy containing the file relative to the bucket name
Example: <tt>:table_name/:id</tt>
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000027-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000027-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu/backends/s3_backend.rb, line 195</span>
195:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">base_path</span>
196:           <span class="ruby-constant">File</span>.<span class="ruby-identifier">join</span>(<span class="ruby-identifier">attachment_options</span>[<span class="ruby-identifier">:path_prefix</span>], <span class="ruby-identifier">attachment_path_id</span>)
197:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000032" class="method-detail">
        <a name="M000032"></a>

        <div class="method-heading">
          <a href="#M000032" class="method-signature">
          <span class="method-name">create_temp_file</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000032-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000032-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu/backends/s3_backend.rb, line 250</span>
250:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">create_temp_file</span>
251:           <span class="ruby-identifier">write_to_temp_file</span> <span class="ruby-identifier">current_data</span>
252:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000033" class="method-detail">
        <a name="M000033"></a>

        <div class="method-heading">
          <a href="#M000033" class="method-signature">
          <span class="method-name">current_data</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000033-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000033-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu/backends/s3_backend.rb, line 254</span>
254:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">current_data</span>
255:           <span class="ruby-constant">S3Object</span>.<span class="ruby-identifier">value</span> <span class="ruby-identifier">full_filename</span>, <span class="ruby-identifier">bucket_name</span>
256:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000025" class="method-detail">
        <a name="M000025"></a>

        <div class="method-heading">
          <a href="#M000025" class="method-signature">
          <span class="method-name">filename=</span><span class="method-args">(value)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Overwrites the base filename writer in order to store the old filename
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000025-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000025-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu/backends/s3_backend.rb, line 183</span>
183:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">filename=</span>(<span class="ruby-identifier">value</span>)
184:           <span class="ruby-ivar">@old_filename</span> = <span class="ruby-identifier">filename</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">filename</span>.<span class="ruby-identifier">nil?</span> <span class="ruby-operator">||</span> <span class="ruby-ivar">@old_filename</span>
185:           <span class="ruby-identifier">write_attribute</span> <span class="ruby-identifier">:filename</span>, <span class="ruby-identifier">sanitize_filename</span>(<span class="ruby-identifier">value</span>)
186:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000028" class="method-detail">
        <a name="M000028"></a>

        <div class="method-heading">
          <a href="#M000028" class="method-signature">
          <span class="method-name">full_filename</span><span class="method-args">(thumbnail = nil)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
The full path to the file relative to the bucket name Example:
<tt>:table_name/:id/:filename</tt>
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000028-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000028-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu/backends/s3_backend.rb, line 201</span>
201:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">full_filename</span>(<span class="ruby-identifier">thumbnail</span> = <span class="ruby-keyword kw">nil</span>)
202:           <span class="ruby-constant">File</span>.<span class="ruby-identifier">join</span>(<span class="ruby-identifier">base_path</span>, <span class="ruby-identifier">thumbnail_name_for</span>(<span class="ruby-identifier">thumbnail</span>))
203:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000030" class="method-detail">
        <a name="M000030"></a>

        <div class="method-heading">
          <span class="method-name">public_filename</span><span class="method-args">(thumbnail = nil)</span>
        </div>
      
        <div class="method-description">
          <p>
Alias for <a href="S3Backend.html#M000029">s3_url</a>
</p>
        </div>
      </div>

      <div id="method-M000035" class="method-detail">
        <a name="M000035"></a>

        <div class="method-heading">
          <a href="#M000035" class="method-signature">
          <span class="method-name">s3_hostname</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000035-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000035-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu/backends/s3_backend.rb, line 262</span>
262:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">s3_hostname</span>
263:           <span class="ruby-constant">Technoweenie</span><span class="ruby-operator">::</span><span class="ruby-constant">AttachmentFu</span><span class="ruby-operator">::</span><span class="ruby-constant">Backends</span><span class="ruby-operator">::</span><span class="ruby-constant">S3Backend</span>.<span class="ruby-identifier">hostname</span>
264:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000036" class="method-detail">
        <a name="M000036"></a>

        <div class="method-heading">
          <a href="#M000036" class="method-signature">
          <span class="method-name">s3_port_string</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000036-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000036-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu/backends/s3_backend.rb, line 266</span>
266:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">s3_port_string</span>
267:           <span class="ruby-constant">Technoweenie</span><span class="ruby-operator">::</span><span class="ruby-constant">AttachmentFu</span><span class="ruby-operator">::</span><span class="ruby-constant">Backends</span><span class="ruby-operator">::</span><span class="ruby-constant">S3Backend</span>.<span class="ruby-identifier">port_string</span>
268:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000034" class="method-detail">
        <a name="M000034"></a>

        <div class="method-heading">
          <a href="#M000034" class="method-signature">
          <span class="method-name">s3_protocol</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000034-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000034-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu/backends/s3_backend.rb, line 258</span>
258:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">s3_protocol</span>
259:           <span class="ruby-constant">Technoweenie</span><span class="ruby-operator">::</span><span class="ruby-constant">AttachmentFu</span><span class="ruby-operator">::</span><span class="ruby-constant">Backends</span><span class="ruby-operator">::</span><span class="ruby-constant">S3Backend</span>.<span class="ruby-identifier">protocol</span>
260:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000029" class="method-detail">
        <a name="M000029"></a>

        <div class="method-heading">
          <a href="#M000029" class="method-signature">
          <span class="method-name">s3_url</span><span class="method-args">(thumbnail = nil)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
All public objects are accessible via a GET request to the S3 servers. You
can generate a url for an object using the <a
href="S3Backend.html#M000029">s3_url</a> method.
</p>
<pre>
  @photo.s3_url
</pre>
<p>
The resulting url is in the form:
<tt>http(s)://:server/:bucket_name/:table_name/:id/:file</tt> where the
<tt>:server</tt> variable defaults to <tt>AWS::S3 URL::DEFAULT_HOST</tt>
(s3.amazonaws.com) and can be set using the configuration parameters in
<tt>RAILS_ROOT/config/amazon_s3.yml</tt>.
</p>
<p>
The optional thumbnail argument will output the thumbnail&#8216;s filename
(if any).
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000029-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000029-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu/backends/s3_backend.rb, line 215</span>
215:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">s3_url</span>(<span class="ruby-identifier">thumbnail</span> = <span class="ruby-keyword kw">nil</span>)
216:           <span class="ruby-constant">File</span>.<span class="ruby-identifier">join</span>(<span class="ruby-identifier">s3_protocol</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">s3_hostname</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">s3_port_string</span>, <span class="ruby-identifier">bucket_name</span>, <span class="ruby-identifier">full_filename</span>(<span class="ruby-identifier">thumbnail</span>))
217:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <h3 class="section-bar">Protected Instance methods</h3>

      <div id="method-M000037" class="method-detail">
        <a name="M000037"></a>

        <div class="method-heading">
          <a href="#M000037" class="method-signature">
          <span class="method-name">destroy_file</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Called in the after_destroy callback
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000037-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000037-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu/backends/s3_backend.rb, line 272</span>
272:           <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">destroy_file</span>
273:             <span class="ruby-constant">S3Object</span>.<span class="ruby-identifier">delete</span> <span class="ruby-identifier">full_filename</span>, <span class="ruby-identifier">bucket_name</span>
274:           <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000038" class="method-detail">
        <a name="M000038"></a>

        <div class="method-heading">
          <a href="#M000038" class="method-signature">
          <span class="method-name">rename_file</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000038-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000038-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu/backends/s3_backend.rb, line 276</span>
276:           <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">rename_file</span>
277:             <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-ivar">@old_filename</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-ivar">@old_filename</span> <span class="ruby-operator">!=</span> <span class="ruby-identifier">filename</span>
278:             
279:             <span class="ruby-identifier">old_full_filename</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">join</span>(<span class="ruby-identifier">base_path</span>, <span class="ruby-ivar">@old_filename</span>)
280: 
281:             <span class="ruby-constant">S3Object</span>.<span class="ruby-identifier">rename</span>(
282:               <span class="ruby-identifier">old_full_filename</span>,
283:               <span class="ruby-identifier">full_filename</span>,
284:               <span class="ruby-identifier">bucket_name</span>,
285:               <span class="ruby-identifier">:access</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">attachment_options</span>[<span class="ruby-identifier">:s3_access</span>]
286:             )
287: 
288:             <span class="ruby-ivar">@old_filename</span> = <span class="ruby-keyword kw">nil</span>
289:             <span class="ruby-keyword kw">true</span>
290:           <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000039" class="method-detail">
        <a name="M000039"></a>

        <div class="method-heading">
          <a href="#M000039" class="method-signature">
          <span class="method-name">save_to_storage</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000039-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000039-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu/backends/s3_backend.rb, line 292</span>
292:           <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">save_to_storage</span>
293:             <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">save_attachment?</span>
294:               <span class="ruby-constant">S3Object</span>.<span class="ruby-identifier">store</span>(
295:                 <span class="ruby-identifier">full_filename</span>,
296:                 (<span class="ruby-identifier">temp_path</span> <span class="ruby-value">? </span><span class="ruby-constant">File</span>.<span class="ruby-identifier">open</span>(<span class="ruby-identifier">temp_path</span>) <span class="ruby-operator">:</span> <span class="ruby-identifier">temp_data</span>),
297:                 <span class="ruby-identifier">bucket_name</span>,
298:                 <span class="ruby-identifier">:content_type</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">content_type</span>,
299:                 <span class="ruby-identifier">:access</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">attachment_options</span>[<span class="ruby-identifier">:s3_access</span>]
300:               )
301:             <span class="ruby-keyword kw">end</span>
302: 
303:             <span class="ruby-ivar">@old_filename</span> = <span class="ruby-keyword kw">nil</span>
304:             <span class="ruby-keyword kw">true</span>
305:           <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>


    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>